﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using TInventory.Reports.Datasets;
using TInventory.Reports;

namespace TInventory
{
    public partial class TIAccountsParent : Form
    {
        private int childFormNumber = 0;

        public TIAccountsParent()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
         //   toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void inventoryToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void inventoryEntriesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InventoryListingForm form = new InventoryListingForm();

            form.MdiParent = this;

            form.Show();
            form.WindowState = FormWindowState.Minimized;
            form.WindowState = FormWindowState.Maximized;
            
        }

        private void supplierEntriesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SupplierListingForm form = new SupplierListingForm();
            
            form.MdiParent = this;
            
            form.Show();
            form.WindowState = FormWindowState.Minimized;
            form.WindowState = FormWindowState.Maximized;

        }

       


        private void typeEntryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddTypeForm typeForm = new AddTypeForm();
            typeForm.MdiParent = this;
            typeForm.Show();
            typeForm.WindowState = FormWindowState.Minimized;
            typeForm.WindowState = FormWindowState.Maximized;
        }

        private void TIAccountsParent_FormClosing(object sender, FormClosingEventArgs e)
        {
            //string dbName = @"E:\Techxion\techxion-products\TI_BAL\TINVENTORY.MDF";
            //string dbServer = ".";
            //SqlConnection.ClearAllPools();
            //using (SqlConnection conn = new SqlConnection(string.Format("Server={0};Database=master;Integrated Security=SSPI", dbServer)))
            //{
            //    conn.Open();
            //    using (SqlCommand cmd = new SqlCommand("sp_detach_db", conn))
            //    {
            //        cmd.CommandType = CommandType.StoredProcedure;
            //        cmd.Parameters.AddWithValue("@dbname", dbName);
            //        cmd.ExecuteNonQuery();
            //    }
            //}
        }

        private void SupplierManagementToolStripMenuItem_Click(object sender, EventArgs e)

            {
            CustomerListingForm form = new CustomerListingForm();

            form.MdiParent = this;

            form.Show();
            form.WindowState = FormWindowState.Minimized;
            
            form.WindowState = FormWindowState.Maximized;

        
        }

        private void subTypeEntryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSubTypeForm subTypeForm = new AddSubTypeForm();
            subTypeForm.MdiParent = this;
            subTypeForm.Show();
            subTypeForm.WindowState = FormWindowState.Minimized;

            subTypeForm.WindowState = FormWindowState.Maximized;
        }
        

        private void sizeEntryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSizeForm sizeForm = new AddSizeForm();
            sizeForm.MdiParent = this;
            sizeForm.Show();

            sizeForm.WindowState = FormWindowState.Minimized;
            sizeForm.WindowState = FormWindowState.Maximized;
        }

        private void TIAccountsParent_Load(object sender, EventArgs e)
        {
            this.Text = System.Configuration.ConfigurationSettings.AppSettings["SoftwareName"];
        }

        private void addEditAccountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEditAccounts accountForm = new AddEditAccounts();
            accountForm.MdiParent = this;
            accountForm.Show();

            accountForm.WindowState = FormWindowState.Minimized;
            accountForm.WindowState = FormWindowState.Maximized;
        }

        private void addEditJournalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEditJournal journalForm = new AddEditJournal();
            journalForm.MdiParent = this;
            journalForm.Show();

            journalForm.WindowState = FormWindowState.Minimized;
            journalForm.WindowState = FormWindowState.Maximized;
        }

        private void saleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaleTransaction saleForm = new SaleTransaction();
            saleForm.parentWindow = this;
            saleForm.MdiParent = this;
            saleForm.Show();

            saleForm.WindowState = FormWindowState.Minimized;
            saleForm.WindowState = FormWindowState.Maximized;
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            PurchaseTransaction purchaseForm = new PurchaseTransaction();
            purchaseForm.MdiParent = this;
            purchaseForm.Show();

            purchaseForm.WindowState = FormWindowState.Minimized;
            purchaseForm.WindowState = FormWindowState.Maximized;

        }

        private void transactionsToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void supplierReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.ReportType = "SupplierReport";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void customerReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.ReportType = "CustomerReport";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {

        }

        private void journalReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportFormWithFilter reportForm = new ReportFormWithFilter();
            reportForm.ReportType = "JournalReport";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void inventoryReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InventoryReportForm reportForm = new InventoryReportForm();
            reportForm.ReportType = "InventoryReport";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void ledgerReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.ReportType = "LedgerReport";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void customerLedgersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportFormCustomer reportForm = new ReportFormCustomer();
                        
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void supplierLedgersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportFormSupplier reportForm = new ReportFormSupplier();

            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutForm form = new AboutForm();
            form.ShowDialog();
        }

        private void toolStripMenuItem3_Click_1(object sender, EventArgs e)
        {
            ReportFormInvoice reportForm = new ReportFormInvoice();
            reportForm.parentForm = this;
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void allPartyRecievablesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.ReportType = "AllPartyRecievable";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }

        private void allPartyPayablesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportForm reportForm = new ReportForm();
            reportForm.ReportType = "AllPartyPayable";
            reportForm.MdiParent = this;
            reportForm.Show();

            reportForm.WindowState = FormWindowState.Minimized;
            reportForm.WindowState = FormWindowState.Maximized;
        }
    }
}
